<?php

use App\Http\CurrentUser;
use Hyperf\Context\ApplicationContext;
use Hyperf\Contract\StdoutLoggerInterface;

if (!function_exists('currentAdminUser')) {
    function currentAdminUser()
    {
        $auth = di(CurrentUser::class);

        return $auth->user();
    }
}
if (!function_exists('currentAdminUserId')) {
    function currentAdminUserId()
    {
        $auth = di(CurrentUser::class);
        return $auth->id();
    }
}

if (!function_exists('stdLog')) {
    function stdLog()
    {
        return container()->get(StdoutLoggerInterface::class);
    }
}
if (! function_exists('container')) {
    /**
     * 获取容器对象
     *
     * @param string $id
     * @return mixed|\Psr\Container\ContainerInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    function container(string $id = ''): mixed
    {
        $container = ApplicationContext::getContainer();

        if ($id) return $container->get($id);

        return $container;
    }
}

if (! function_exists('di')) {
    /**
     * @param string $id
     * @return mixed
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    function di(string $id = ''): mixed
    {
        return container($id);
    }
}
